package ejercicio2;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.swing.table.DefaultTableModel;


public class prestatarioXcliente extends javax.swing.JFrame {
        DefaultTableModel modeloTabla =new DefaultTableModel();
        int Contador;
    /**
     * Creates new form Prestatario_Cliente
     */
    public prestatarioXcliente() {
        initComponents();
        TabInnerJoin.setModel(modeloTabla);
        modeloTabla.addColumn("CodPrestatario");
        modeloTabla.addColumn("CodCliente");
        modeloTabla.addColumn("NombresPrestatario");
        modeloTabla.addColumn("LimiteCredito");
        modeloTabla.addColumn("CodCliente");
        modeloTabla.addColumn("NombreCliente");
        modeloTabla.addColumn("Apellidos");
        modeloTabla.addColumn("Telefono");
        modeloTabla.addColumn("Direccion");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TabPrestatario = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TabCliente = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        txtCodPrestatario = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        TabInnerJoin = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PRESTATARIO |X| CLIENTE ");

        jPanel1.setBackground(new java.awt.Color(0, 0, 204));

        jLabel2.setText("Tabla Prestatario:");

        TabPrestatario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"P0001", "C0002", "nombre_prestatario1", "20000"},
                {"P0002", "C0005", "nombre_prestatario2", "10000"},
                {"P0003", "C0005", "nombre_prestatario3", "50000"},
                {"P0004", "C0001", "nombre_prestatario4", "30000"},
                {"P0005", "C0003", "nombre_prestatario5", "80000"}
            },
            new String [] {
                "CodPrestatario", "CodCliente", "Nombres", "Limite de Credito"
            }
        ));
        jScrollPane1.setViewportView(TabPrestatario);

        jLabel3.setText("Tabla Cliente:");

        TabCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"C0001", "nombre_cliente1", "apellido1", "123", "direccion1"},
                {"C0002", "nombre-cliente2", "apellido2", "345", "direccion2"},
                {"C0003", "nombre_cliente3", "apellido3", "567", "direccion3"},
                {"C0004", "nombre_cliente4", "apellido4", "789", "direccion4"}
            },
            new String [] {
                "CodCliente", "NombreCliente", "Apellidos", "Telefono", "Direccion"
            }
        ));
        jScrollPane2.setViewportView(TabCliente);

        jLabel1.setText("CodPrestatario:");

        jButton1.setText("Prestatario|X|Cliente");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        TabInnerJoin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(TabInnerJoin);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(0, 40, Short.MAX_VALUE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(119, 119, 119)
                        .addComponent(jButton1)
                        .addGap(60, 60, 60)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtCodPrestatario, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane3))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addGap(106, 106, 106))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(44, 44, 44)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(txtCodPrestatario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1))
                .addGap(17, 17, 17)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        Object[] fila=new Object[9];
        String CodCliente;
        String CodPrestatario;
        //for(int i=contador;i< TabPrestatario.getRowCount();i++)
        //{
        if(Contador<TabPrestatario.getRowCount())
        {
            txtCodPrestatario.setText(TabPrestatario.getValueAt(Contador, 0).toString());
            CodPrestatario=TabPrestatario.getValueAt(Contador, 1).toString();
            for(int j=0;j< TabCliente.getRowCount();j++)
            {
                CodCliente=TabCliente.getValueAt(j, 0).toString();
                if(CodPrestatario==CodCliente)
                {
                    fila[0]=TabPrestatario.getValueAt(Contador, 0).toString();
                    fila[1]=TabPrestatario.getValueAt(Contador, 1).toString();
                    fila[2]=TabPrestatario.getValueAt(Contador, 2).toString();
                    fila[3]=TabPrestatario.getValueAt(Contador, 3).toString();
                    fila[4]=TabCliente.getValueAt(j, 0).toString();
                    fila[5]=TabCliente.getValueAt(j, 1).toString();
                    fila[6]=TabCliente.getValueAt(j, 2).toString();
                    fila[7]=TabCliente.getValueAt(j, 3).toString();
                    fila[8]=TabCliente.getValueAt(j, 4).toString();
                    modeloTabla.addRow(fila);
                }
            }
            Contador++;
        }     
        //}
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(prestatarioXcliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(prestatarioXcliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(prestatarioXcliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(prestatarioXcliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new prestatarioXcliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable TabCliente;
    private javax.swing.JTable TabInnerJoin;
    private javax.swing.JTable TabPrestatario;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextField txtCodPrestatario;
    // End of variables declaration//GEN-END:variables
}
